#!/bin/bash
set -e

cd $(dirname $0)/..

echo Running validation

PACKAGES="$(go list ./...)"

if [ ! -e build/data ];then
    mkdir -p build/data
fi

go generate

echo Running: go vet
go vet ${PACKAGES}
echo Running: gometalinter
for i in ${PACKAGES}; do
    if [ -n "$(gometalinter $i | \
        grep -v 'pkg/data/zz_generated_bindata.go' | \
        grep -v 'should have comment.*or be unexported' | \
        grep -v 'cli/cmd.*don.t use underscores in Go name' | \
        grep -v 'cli/cmd.*should be DNS' | \
        tee /dev/stderr)" ]; then
        failed=true
    fi
done
test -z "$failed"
echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | \
        grep -v 'pkg/data/zz_generated_bindata.go' | \
        tee /dev/stderr)"

. ./scripts/version.sh

if [ -n "$DIRTY" ]; then
    echo Source dir is dirty
    git status --porcelain --untracked-files=no
    exit 1
fi
